# coding=utf-8
import logging
import datetime
import sys


class CustomLogger(object):
    def __init__(self, log_level="INFO"):
        self.log_level = log_level
        self.log_level_map = {"DEBUG": 10, "INFO": 8, "WARN": 6, "ERROR": 3, "CRITICAL": 1}

    @staticmethod
    def _output(log_level, message):
        print("[%s] %s" % (log_level, message))

    def debug(self, message):
        if self.log_level_map[self.log_level] >= 10:
            self._output("DEBUG", message)

    def info(self, message):
        if self.log_level_map[self.log_level] >= 8:
            self._output("INFO", message)

    def warning(self, message):
        if self.log_level_map[self.log_level] >= 6:
            self._output("WARN", message)

    def error(self, message):
        if self.log_level_map[self.log_level] >= 3:
            self._output("ERROR", message)

    def critical(self, message):
        if self.log_level_map[self.log_level] >= 1:
            self._output("CRITICAL", message)


logger = CustomLogger()

# logger = logging.getLogger('mylogger')
# logger.setLevel(logging.DEBUG)
# rf_handler = logging.StreamHandler(sys.stdout)
# rf_handler.setLevel(logging.DEBUG)
# # rf_handler = logging.handlers.TimedRotatingFileHandler('all.log', when='midnight', interval=1, backupCount=7, atTime=datetime.time(0, 0, 0, 0))
# rf_handler.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(message)s"))
#
# # f_handler = logging.FileHandler('error.log')
# # f_handler.setLevel(logging.INFO)
# # f_handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(filename)s[:%(lineno)d] - %(message)s"))
#
# logger.addHandler(rf_handler)
# # logger.addHandler(f_handler)
